package graphics.seal;

import java.awt.BorderLayout;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JLabel;

public class TestFont extends Frame implements ItemListener {
	private static final long serialVersionUID = 1L;
	Choice c;
	JLabel l;

	public static void main(String[] args) {
		new TestFont();
	}

	public TestFont() {
		super();
		initialize();
	}

	private void initialize() {
		this.setSize(300, 200);
		this.setTitle("Frame");
		GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
		String fontName[] = g.getAvailableFontFamilyNames();
		c = new Choice();
		for (int i = 0; i < fontName.length; i++)
			c.add(fontName[i]);
		l = new JLabel("", JLabel.CENTER);
		this.add(c, BorderLayout.NORTH);
		this.add(l, BorderLayout.CENTER);
		this.setVisible(true);
		c.addItemListener(this);
		this.addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent e) {
				System.exit(0);
			}
		});
	}

	public void itemStateChanged(ItemEvent e) {
		String name = (String) e.getItem();
		System.out.println(name);
		Font f = new Font(name, Font.ITALIC, 40);
		l.setForeground(Color.red);
		l.setFont(f);
		l.setText("测试字体");
		double x = l.getLocation().getX();
		double y = l.getLocation().getY();
		int h = l.getSize().height;
		int w = l.getSize().width;
		System.out.println(x + "," + y);
		System.out.println(h + "," + w);
	}
}
